package com.soft.demo02;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    String str;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_ui);
        Button btn20 = findViewById(R.id.button20);
        final RadioGroup rg1 =(RadioGroup) findViewById(R.id.RadioGroup01);


        rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton rd1 =(RadioButton) findViewById(R.id.radioButton);
                //str = rd1.getText().toString();
            }
        });
        btn20.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for(int i = 0; i < rg1.getChildCount();i++){
                    RadioButton rt =(RadioButton) rg1.getChildAt(i);
                    if(rt.isChecked()){
                        Toast.makeText(MainActivity.this,rt.getText(),Toast.LENGTH_LONG).show();
                        AlertDialog.Builder al = new AlertDialog.Builder(MainActivity.this);
                        al.setMessage("4444444444");
                        al.setPositiveButton("确定",null).show();
                        break;
                    }
                }

            }
        });
    }
}
